package org.NooLab.glue.instances;

import java.io.Serializable;
import java.util.Vector;


/**
 * 
 * 
 * 
 *
 */
public class DeliveryObjects  implements Serializable{
 
	transient private static final long serialVersionUID = 4724991273197233534L;
	 
	
	Vector<DeliveryObject> deliveryObjects = new Vector<DeliveryObject> ();
	 
	
	public DeliveryObjects(){
		
	}


	public Vector<DeliveryObject> getDeliveryObjects() {
		return deliveryObjects;
	}


	public void setDeliveryObjects(Vector<DeliveryObject> deliveryObjects) {
		this.deliveryObjects = deliveryObjects;
	}


	public void add( DeliveryObject dobj) {
		 
		deliveryObjects.add(dobj) ;
	}


	public int size() {
		 
		return  deliveryObjects.size() ;
	}


	public DeliveryObject get(int index) {
		DeliveryObject dobj=null;
		
		dobj = deliveryObjects.get(index) ;
		
		return dobj;
	}


	public void remove(int index) {
		
		deliveryObjects.remove(index) ;
	}


	/**
	 * object storage for the waiting queue
	 * 
	 */
	public void save(String filename) {
		 
		
		
	}

	public int indexOfByTransactionID(long transactionID){
		int index=-1;
		DeliveryObject dobj;
		
		
		for (int i=0;i<deliveryObjects.size();i++){
		
			dobj = deliveryObjects.get(i) ;
			
			if (dobj.getTransactionID() == transactionID ){
				index=i;
				break;
			}
		}
		
		return index;
	}
	
	public void removeByTransactionID(long transactionID) {
		
		int index ;
		index = indexOfByTransactionID(transactionID);
		
		if (index>=0){
			deliveryObjects.remove(index) ;
		}
		
	}


	public int candicount() {

		int n=0;
		DeliveryObject dobj;
		
		for (int i=0;i<deliveryObjects.size();i++){
			
			dobj = deliveryObjects.get(i) ;
			
			if (dobj.isSendingProcessRunning()==false){
				n++;
			}
		}
		
		return n;
	}
	
	
	
}
